/**
 * @date 3:40:07 PM
 * SMSController.java
 * Administrator
 * TODO
 */
package com.qs.education.controllers;

import javax.servlet.http.HttpServletRequest;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.qs.education.bean.api.PageBean;
import com.qs.education.bean.api.ResponseBean;
import com.qs.education.bean.api.ResponseListBean;
import com.qs.education.bean.beans.EducationSMSResponse;
import com.qs.education.bean.entity.EducationSMS;
import com.qs.education.bean.enums.ResponseStatus;
import com.qs.education.bean.utils.JsonUtil;
import com.qs.education.service.ISMSAPIService;

/**
 * @class SMSController	
 * @author Warren
 * @description
 * @date Nov 5, 2018 
 */
@RestController
public class SMSController {
	
	@Autowired
	private ISMSAPIService smsAPIService;
	private final Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * @author Warren
	 * @param mobile
	 * @return Map<String,Object>
	 * @description 根据手机号获取验证码
	 * @date Nov 5, 2018
	 */
	@RequestMapping("/getSMSAPI")
	public EducationSMSResponse getSMS(EducationSMS obj,HttpServletRequest request) {
		log.info("api");
		EducationSMSResponse response = smsAPIService.getSMS(obj);
		response.setToken(response.getToken(request));
		return response;
	}
	
	/**
	 * @author Warren
	 * @param mobile 手机号
	 * @param code 验证码
	 * @param request 
	 * @return ResponseBean
	 * @description 校验验证码
	 * @date Nov 5, 2018
	 */
	@RequestMapping("/checkSMSAPI")
	public ResponseBean checkSMS(String mobile,String code,HttpServletRequest request) {
		log.info("api");
		ResponseBean response = smsAPIService.checkSMS(mobile, code);
		response.setToken(response.getToken(request));
		return response;
	}
	
	
	/**
	 * @Description 得到所有符合条件的SMS
	 * @author Jason
	 * @date Nov 22, 2018
	 * @param request
	 * @param sms
	 * @param currentPage
	 * @param pageSize
	 * @return
	 */
	@RequestMapping("/getSMSListAPI")
	public PageBean getSMSList(HttpServletRequest request,String sms,Integer currentPage,Integer pageSize) {
		
		log.info("api SMS 端 Controller  getSMSList ");
		EducationSMS educationSMS = (EducationSMS) JsonUtil.jsonToBean(sms, EducationSMS.class);
		PageBean response = new PageBean();
		response.setToken(response.getToken(request));
		response = smsAPIService.getSMSList(educationSMS,currentPage,pageSize);
		response.setStatus(ResponseStatus.SUCCESS.toString());
		
		return response;
	}
	
	/**
	 * @Description 根据ID查询SMS
	 * @author Jason
	 * @date Nov 22, 2018
	 * @param request
	 * @param Id
	 * @return
	 */
	@RequestMapping("/deleteSMSByIdAPI")
	public ResponseBean deleteSMSById(HttpServletRequest request,Integer Id) {
		
		log.info("api SMS 端 Controller  deleteSMSByIdAPI ");

		ResponseBean response = new ResponseBean();
		response.setToken(response.getToken(request));
		Boolean result = smsAPIService.deleteSMSById(Id);
		if (result) {
			response.setStatus(ResponseStatus.SUCCESS.toString());
		} else {
			response.setStatus(ResponseStatus.FAILED.toString());
		}
		
		
		return response;
	}
}
